#include "UtilWidget.h"

#if (QT_VERSION < QT_VERSION_CHECK(5,14,0))
#include <QDesktopWidget>
#endif

QIcon UtilWidget::StdIcon(QStyle::StandardPixmap stdIcon)
{
    QStyle* style = QApplication::style();
    QIcon icon = style->standardIcon(stdIcon);
    //    QPixmap m_pic = icon.pixmap(icon.actualSize(QSize(LIco->width()-9,LIco->height()-5)));//size自行调整
    return icon;
}

void UtilWidget::setPosition(QWidget *parents, UtilWidget::POSITION position)
{
    switch (position) {

    case POSITION::LeftTOP:
        ToLeft(parents,Qt::AlignTop);
        break;
    case POSITION::LeftCenter:
        ToLeft(parents);
        break;
    case POSITION::LeftBottom:
        ToLeft(parents,Qt::AlignBottom);
        break;
    case POSITION::HVCenter:
        ToCenter(parents);
        break;
    case POSITION::RightTOP:
        ToRight(parents,Qt::AlignLeft);
        break;
    case POSITION::RightCenter:
        ToRight(parents);
        break;
    case POSITION::RightBottom:
        ToRight(parents,Qt::AlignBottom);
        break;
    default:
        break;
    }
    return;
}


void UtilWidget::ToCenter(QWidget *parents)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
    QRect RectObj = parents->screen()->geometry();
    int win_wid = RectObj.width() - parents->width();
    int win_hig = RectObj.height() - parents->height();
    parents->move( win_wid  / 2, win_hig / 2.5);

#else
    parents->move (
        (QApplication::desktop()->width() - parents->width())/2,
        (QApplication::desktop()->height() - parents->height())/2.5
        );
#endif

}

void UtilWidget::ToRight(QWidget *parents,Qt::Alignment alignment)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
    parents->setGeometry(QStyle::alignedRect(
        Qt::RightToLeft,
        alignment,
        parents->size(),
        parents->screen()->availableGeometry()));
#else
    parents->move (
        (QApplication::desktop()->width() - parents->width()),
        (QApplication::desktop()->height() - parents->height())/2.5
        );
#endif
}
void UtilWidget::ToLeft(QWidget *parents, Qt::Alignment alignment)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
    parents->setGeometry(QStyle::alignedRect(
        Qt::LeftToRight,
        alignment,
        parents->size(),
        parents->screen()->availableGeometry())
                         );
#else
    parents->move (
        (QApplication::desktop()->width() - parents->width()),
        (QApplication::desktop()->height()/2 - parents->height())
        );
#endif
}
